{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "<font color=\"#a9a56c\" size=2> **@Author: Arif Kasim Rozani - (Team Operation Badar)** </font>\n",
        "\n"
      ],
      "metadata": {
        "id": "0AyF8L7ythkk"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "# **Operator and Operand**\n",
        "\n",
        "In Python (and programming in general), an operand is a value or variable that an operator acts on. Think of it like this:\n",
        "\n",
        "* **Operator**: A symbol that performs an operation (e.g., +, -, *, /).\n",
        "* **Operand**: The value(s) or variable(s) that the operator works with.\n",
        "\n"
      ],
      "metadata": {
        "id": "kUj3ZR9opjy1"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "![Operand.jpg]()"
      ],
      "metadata": {
        "id": "iP8OEzBior0c"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Key Points:**\n",
        "\n",
        "* Operands are the \"inputs\" for an operator.\n",
        "* The number of operands depends on the operator:\n",
        "    * **Unary operators** (e.g., not, -) work with one operand.\n",
        "    * **Binary operators** (e.g., +, -, *, /) work with two operands."
      ],
      "metadata": {
        "id": "CTT_1AJ6qvFT"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Unary Operators**\n",
        "Unary operators work with one operand (a single value or variable). They perform operations on just one thing.\n",
        "\n",
        "## **Examples:**\n",
        "1.  **Negative (-):**\n",
        "      * Changes the sign of the operand."
      ],
      "metadata": {
        "id": "QNELTk_Aqwaa"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "x = 5\n",
        "y = -x  # y is now -5\n",
        "print(\"y = \", y)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "DxucQxEeq_QE",
        "outputId": "e7338161-6551-4e21-b47c-00b35a8491f7"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "y =  -5\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "2.  **Logical NOT (not):**\n",
        "      * Reverses a boolean value."
      ],
      "metadata": {
        "id": "ELdIaVv-rDZr"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "a = True\n",
        "b = not a  # b is now False\n",
        "print(\"b = \", b)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "kJpOJBLgrHrS",
        "outputId": "ced44b6d-6b37-40a5-eed5-2a4b8b32e937"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "b =  False\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Bitwise NOT (~):**\n",
        "\n",
        "  * Inverts the bits of a number (used in binary operations)."
      ],
      "metadata": {
        "id": "hqHcAq2m6-eO"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "x: int = 5  # Binary: 0101\n",
        "y: int = ~x  # y is now -6 (binary: 1010, but in two's complement form)\n",
        "print(\"y = \", y)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "Gccj_RS57FNn",
        "outputId": "8fb006ef-8466-4809-ff5d-f551bb4fd661"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "y =  -6\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "You can print an integer as a binary number in Python using the `bin()` function. Here's an example:\n",
        "\n",
        "The binary string is prefixed with `'0b'` to indicate that it's a binary number."
      ],
      "metadata": {
        "id": "ILf10RoZ8h1l"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print(\"bin(x) = \",bin(x), type(bin(x)))"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "dFcFEnFj7kFO",
        "outputId": "3f176c6f-d841-4f86-ab07-def0b35687ca"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "bin(x) =  0b101 <class 'str'>\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "num: int = x\n",
        "print(format(num, 'b'))  # Output: 1010\n",
        "print(f\"{num:b}\")  # Output: 1010"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "ydzfRnN68KvF",
        "outputId": "90d9ea05-2f9c-44ab-932b-256bdb20bbd0"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "101\n",
            "101\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Binary Operators**\n",
        "\n",
        "Binary operators work with two operands (two values or variables). They perform operations between two things.\n",
        "\n",
        "### **Examples:**\n",
        "\n",
        "1. **Arithmetic Operators (+, -, *, /, etc.):**\n",
        "    * Perform basic math operations.\n",
        "\n",
        "2. **Comparison Operators (==, !=, >, <, etc.):**\n",
        "    * Compare two values and return True or False.\n",
        "\n",
        "3. **Logical Operators (and, or):**\n",
        "    * Combine boolean values.\n",
        "\n",
        "4. **Assignment Operators (=, +=, -=, etc.):**\n",
        "    * Assign values to variables or perform operations while assigning.\n",
        "\n",
        "<br>\n",
        "\n",
        "Note: (we will see these operators in action in next topic)\n"
      ],
      "metadata": {
        "id": "aSaWKsKY_W5S"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Key Difference:**\n",
        "\n",
        "1.  **Unary Operators**: Work with one operand (e.g., -x, not a).\n",
        "2.  **Binary Operators**: Work with two operands (e.g., a + b, x > y)."
      ],
      "metadata": {
        "id": "yDyAkHDAAFRq"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "# **Operators in Python**\n",
        "Operators in Python are `symbols` used to perform operations on variables and values. Python supports several types of operators:\n",
        "\n"
      ],
      "metadata": {
        "id": "N6zXNS9Mom_N"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "\n",
        "\n",
        "##**1. Arithmetic Operators**\n",
        "Used for basic mathematical operations.\n",
        "\n",
        "<br>\n",
        "\n",
        "| Operator | Name                | Example                           |\n",
        "|----------|---------------------|-----------------------------------|\n",
        "| +        | Addition            | 5 + 2 = 7                         |\n",
        "| -        | Subtraction         | 5 - 2 = 3                         |\n",
        "| *        | Multiplication      | 5 * 2 = 10                        |\n",
        "| /        | Division (float)    | 5 / 2 = 2.5                       |\n",
        "| //       | Floor Division      | 5 // 2 = 2 (removes decimal part) |\n",
        "| %        | Modulus (remainder) | 5 % 2 = 1                         |\n",
        "| **       | Exponentiation      | 5 ** 2 = 25                       |\n",
        "|          |                     |                                   |\n",
        "\n",
        "\n",
        "<br>\n",
        "\n",
        "### **Example**"
      ],
      "metadata": {
        "id": "NzFDWVWLiCQS"
      }
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "Kg-aA726ez1q",
        "outputId": "1638027a-b9f3-4463-e02b-4de7cb8bb3c4"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "a + b  =  13\n",
            "a - b  =  7\n",
            "a * b  =  30\n",
            "a / b  =  3.3333333333333335\n",
            "a // b =  3\n",
            "a % b  =  1\n",
            "a % b  =  1000\n"
          ]
        }
      ],
      "source": [
        "a: int = 10\n",
        "b: int = 3\n",
        "print(\"a + b  = \", a + b)   # 13 Addition\n",
        "print(\"a - b  = \", a - b)   # 7 Subtraction\n",
        "print(\"a * b  = \", a * b)   # 30 Multiplication\n",
        "print(\"a / b  = \", a / b)   # 3.3333333333333335\n",
        "print(\"a // b = \", a // b)  # 3 Floor Division\n",
        "print(\"a % b  = \", a % b)   # 1 Modulus (remainder)\n",
        "print(\"a % b  = \", a ** b)  # 1000 Exponentiation (10 * 10 * 10)"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **2. Comparison (Relational) Operators**\n",
        "Used to compare two values.\n",
        "\n",
        "<br>\n",
        "\n",
        "| Operator | Name                  | Example        |\n",
        "|----------|-----------------------|----------------|\n",
        "| ==       | Equal                 | 5 == 5 → True  |\n",
        "| !=       | Not equal             | 5 != 3 → True  |\n",
        "| >        | Greater than          | 5 > 3 → True   |\n",
        "| <        | Less than             | 5 < 3 → False  |\n",
        "| >=       | Greater than or equal | 5 >= 5 → True  |\n",
        "| <=       | Less than or equal    | 5 <= 3 → False |\n",
        "|          |                       |                |\n",
        "|          |                       |                |  \n",
        "\n",
        "<br>\n",
        "\n",
        "### **Example**"
      ],
      "metadata": {
        "id": "c_a4lukqlDdA"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "x: int = 10\n",
        "y: int = 5\n",
        "\n",
        "print(\"x == y = \", x == y)  # False, Equal\n",
        "print(\"x != y = \", x != y)  # True, Not equal\n",
        "print(\"x > y  = \", x > y)   # True, Greater than\n",
        "print(\"x < y  = \", x < y)   # False, Less than\n",
        "print(\"x >= y = \", x >= y)  # True, Greater than or equal\n",
        "print(\"x <= y = \", x <= y)  # False, Less than or equal"
      ],
      "metadata": {
        "id": "FqfXH7Zll2zn",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "b82e9319-3c39-4a04-d80b-c494c9500abb"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "x == y =  False\n",
            "x != y =  True\n",
            "x > y  =  True\n",
            "x < y  =  False\n",
            "x >= y =  True\n",
            "x <= y =  False\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "Contributor: Hadiqa Gohar from Karachi\n",
        "## **❓What Are Chained Comparison Operators?**\n"
      ],
      "metadata": {
        "id": "OCqjZY6usFia"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "In Python, we can chain comparison operators together to express multiple comparisons in a single line. This allows for more readable and concise code. Rather than writing multiple comparisons with the same variable repeatedly, Python lets us combine them.\n"
      ],
      "metadata": {
        "id": "RPi7qBK9sKxK"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Example:**\n"
      ],
      "metadata": {
        "id": "WKXMd_sdsgI5"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "x: int = 15\n",
        "if 10 < x < 20:\n",
        "    print(\"x is between 10 and 20\")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "KqCdxvUMskaI",
        "outputId": "a1ef472a-3f6a-4501-9b6f-687210da28b8"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "x is between 10 and 20\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "```python\n",
        "#Internally, Python interprets this as:\n",
        "if 10 < x and x < 20:\n",
        "    print(\"x is between 10 and 20\")\n",
        "```"
      ],
      "metadata": {
        "id": "1cyHzsins3pw"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **3. Logical Operators**\n",
        "Used to combine conditional statements.\n",
        "\n",
        "<br>\n",
        "\n",
        "| Operator | Name        | Example                   |\n",
        "|----------|-------------|---------------------------|\n",
        "| and      | Logical AND | (5 > 3 and 10 > 5) → True |\n",
        "| or       | Logical OR  | (5 > 3 or 10 < 5) → True  |\n",
        "| not      | Logical NOT | not(5 > 3) → False        |\n",
        "\n",
        "\n",
        "<br>\n",
        "\n",
        "### **Example**"
      ],
      "metadata": {
        "id": "h6eJKBK0m14d"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "x: bool = True\n",
        "y: bool = False\n",
        "\n",
        "print(\"x and y = \", x and y)  # False\n",
        "print(\"x or y  = \", x or y)   # True\n",
        "print(\"not x   = \", not x)    # False"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "020TPK6ynfl9",
        "outputId": "35ba46e5-df8d-4bac-af75-77d004c59634"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "x and y =  False\n",
            "x or y  =  True\n",
            "not x   =  False\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **4. Assignment Operators**\n",
        "Used to assign values to variables.\n",
        "\n",
        "<br>\n",
        "\n",
        "| Operator | Example | Equivalent To |\n",
        "|----------|---------|---------------|\n",
        "| =        | x = 5   | x = 5         |\n",
        "| +=       | x += 3  | x = x + 3     |\n",
        "| -=       | x -= 3  | x = x - 3     |\n",
        "| *=       | x *= 3  | x = x * 3     |\n",
        "| /=       | x /= 3  | x = x / 3     |\n",
        "| //=      | x //= 3 | x = x // 3    |\n",
        "|          |         |               |\n",
        "|          |         |               |\n"
      ],
      "metadata": {
        "id": "rjEUF7mWpJ3U"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "x = 5\n",
        "print(\"Assignment: x = 5                    \",x)  # Output: 5\n",
        "\n",
        "x += 3  # Equivalent to x = x + 3\n",
        "print(\"Addition Assignment: x += 3          \",x)  # Output: 8\n",
        "\n",
        "x -= 3  # Equivalent to x = x - 3\n",
        "print(\"Subtraction Assignment: x -= 3       \",x)  # Output: 5\n",
        "\n",
        "x *= 3  # Equivalent to x = x * 3\n",
        "print(\"Multiplication Assignment: x *= 3    \",x)  # Output: 15\n",
        "\n",
        "x /= 3  # Equivalent to x = x / 3\n",
        "print(\"Division Assignment: x /= 3          \",x)  # Output: 5.0\n",
        "\n",
        "x //= 3  # Equivalent to x = x // 3\n",
        "print(\"Floor Division Assignment: x //= 3   \",x)  # Output: 1.0"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "WL0jnZ5HrvAB",
        "outputId": "fd4176b8-1b13-4a51-bf57-e34ecd3af26a"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Assignment: x = 5                     5\n",
            "Addition Assignment: x += 3           8\n",
            "Subtraction Assignment: x -= 3        5\n",
            "Multiplication Assignment: x *= 3     15\n",
            "Division Assignment: x /= 3           5.0\n",
            "Floor Division Assignment: x //= 3    1.0\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "Why Use Shorthand Operators?\n",
        "\n",
        "* `Readability`: Makes the code more concise and easier to read.\n",
        "* `Efficiency`: Reduces the need to repeat the variable name.\n",
        "* `Common Practice`: Widely used in Python and other programming languages."
      ],
      "metadata": {
        "id": "mAYIYPsxtny4"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **walrus operator**"
      ],
      "metadata": {
        "id": "xhbA8zl7p92Y"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "\n",
        "\n",
        "-   The **walrus operator** `:=` was introduced in Python 3.8.\n",
        "    \n",
        "-   It allows **assignment and evaluation** in a single expression.\n",
        "    \n",
        "-   Great for use in **loops** or **conditional statements** to reduce redundancy.\n",
        "    \n",
        "-   Example: `if (n := len(data)) > 10:` assigns and checks in one go.\n",
        "    \n",
        "-   It improves readability and efficiency when used wisely!"
      ],
      "metadata": {
        "id": "d0vIGx57qmb-"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "if (user_input := input(\"Enter a number: \")) and user_input.isdigit():\n",
        "    print(f\"user_input =  {user_input}\")\n",
        "else:\n",
        "    print(\"Invalid input. Please enter a valid number.\")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "2_3QHUGkq9XF",
        "outputId": "9dbed816-d628-46b0-d003-20689aa324d9"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Enter a number: 7\n",
            "user_input =  7\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **5. Identity Operators**\n",
        "Used to compare `memory locations.`\n",
        "\n",
        "<br>\n",
        "\n",
        "| Operator | Name                                                         | Example    |\n",
        "|----------|--------------------------------------------------------------|------------|\n",
        "| is       | Returns True if objects have the same memory location        | x is y     |\n",
        "| is not   | Returns True if objects do not have the same memory location | x is not y |\n",
        "\n",
        "\n",
        "### **Example**"
      ],
      "metadata": {
        "id": "bzOOHWRZu31v"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "a: list = [1, 2, 3]\n",
        "b: list = [1, 2, 3]\n",
        "c: list = a\n",
        "\n",
        "print(\"a is c     =  \",a is c)       # True  (same object, sharing same memmory space)\n",
        "print(\"a is b     =  \",a is b)       # False (different objects, seperate memmory space)\n",
        "print(\"a == b     =  \", a == b)      # True  (same values, different memmory space but having same vlaues)\n",
        "print(\"a is not b =  \", a is not b)  # True  (True because of different memmory space, although having same memmory space)\n",
        "\n",
        "print('\\n-----\\n') # seperator for better output readability\n",
        "\n",
        "print(\"id(a) = \", id(a))\n",
        "print(\"id(b) = \", id(b))\n",
        "print(\"id(c) = \", id(c))"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "eU9lonCFvTU2",
        "outputId": "6aa5ef39-2faa-407e-e18e-4f08aa0c9eb8"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "a is c     =   True\n",
            "a is b     =   False\n",
            "a == b     =   True\n",
            "a is not b =   True\n",
            "\n",
            "-----\n",
            "\n",
            "id(a) =  134193929171776\n",
            "id(b) =  134193940649408\n",
            "id(c) =  134193929171776\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **6. Membership Operators**\n",
        "Used to check if a value is in a sequence (list, tuple, set, dictionary, etc.).\n",
        "\n",
        "<br>\n",
        "\n",
        "| Operator | Name                                         | Example       |\n",
        "|----------|----------------------------------------------|---------------|\n",
        "| in       | Returns True if value is in the sequence     | x in list     |\n",
        "| not in   | Returns True if value is NOT in the sequence | x not in list |"
      ],
      "metadata": {
        "id": "eKoiVlGVv7am"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "my_list: list = [1, 2, 3, 4, 5]\n",
        "\n",
        "print(\"my_list           = \", my_list)            # [1, 2, 3, 4, 5]\n",
        "print(\"3 in my_list      = \", 3 in my_list)       # True\n",
        "print(\"10 not in my_list = \", 10 not in my_list)  # True\n",
        "\n",
        "print(\"\\n-----\\n\")\n",
        "\n",
        "my_string: str = \"Operation Badar\"\n",
        "\n",
        "print(\"my_string                 = \", my_string)                # Operation Badar\n",
        "print(\"'O' in my_string          = \", 'O' in my_string)         # True\n",
        "print(\"'Hello' not in my_string  = \", 'Hello' not in my_string) # True"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "vHeGeUASwQqV",
        "outputId": "08b06acb-1cc4-405c-fb45-990feb5be7b9"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "my_list           =  [1, 2, 3, 4, 5]\n",
            "3 in my_list      =  True\n",
            "10 not in my_list =  True\n",
            "\n",
            "-----\n",
            "\n",
            "my_string                 =  Operation Badar\n",
            "'O' in my_string          =  True\n",
            "'Hello' not in my_string  =  True\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# **Python Keywords**\n",
        "\n",
        "Keywords in Python are `reserved words` that have special meanings and serve specific purposes in the language syntax. Python keywords cannot be used as the names of variables, functions, and classes or any other identifier."
      ],
      "metadata": {
        "id": "URVRI3DkwnL2"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import keyword\n",
        "\n",
        "# Line continuation (`\\`) allows printing a statement over multiple lines, improving code readability without breaking the string.\n",
        "print(\"The list of \\\n",
        "keywords is : \")\n",
        "\n",
        "# printing all keywords at once using \"kwlist()\"\n",
        "print(keyword.kwlist)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "4_OKCdd_w-Ql",
        "outputId": "0223bde8-011d-4dcc-8d81-377ecda98a67"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The list of keywords is : \n",
            "['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "You cant use keywords/ reserved words as variable name.\n",
        "Uncomment below line to see error"
      ],
      "metadata": {
        "id": "GXl6xedswFaj"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "#and: bool = True"
      ],
      "metadata": {
        "id": "jtChUWWuv5tM"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "# **Python Variables**\n",
        "\n",
        "In Python, variables are used to store data that can be referenced and manipulated during program execution. A variable is essentially a name that is assigned to a value. Unlike many other programming languages, **Python variables do not require explicit declaration of type. The type of the variable is `inferred` based on the value assigned.**\n",
        "\n",
        "(**`inferred`** *meaning deduce or conclude (something) from evidence and reasoning rather than from explicit statements.*)\n",
        "\n",
        "\n",
        "Variables act as placeholders for data. They allow us to store and reuse values in our program.\n",
        "\n",
        "<br>\n",
        "\n",
        "\n",
        "## **Rules for Naming Variables**\n",
        "To use variables effectively, we must follow Python’s naming rules:\n",
        "\n",
        "* Variable names can only contain `letters, digits and underscores` (`_`).\n",
        "* A variable name `cannot` start with a `digit`.\n",
        "* Variable names are `case-sensitive` (`myVar` and `myvar` are different).\n",
        "* Avoid using Python keywords (e.g., if, else, for) as variable names.\n"
      ],
      "metadata": {
        "id": "N4TYXpqnyE1-"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "``` python\n",
        "# Valid variable names\n",
        "name = \"Alice\"\n",
        "_age = 25\n",
        "salary2024 = 50000\n",
        "my_variable = \"Python\"\n",
        "\n",
        "# Invalid variable names\n",
        "2name = \"Bob\"          # ❌ Starts with a digit\n",
        "my-variable = \"Error\"  # ❌ Contains a hyphen\n",
        "class = \"CS101\"        # ❌ Uses a reserved keyword\n",
        "```"
      ],
      "metadata": {
        "id": "PNqlc8Jt1IWB"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Different naming conventions**\n",
        "\n",
        "[Naming Conventions — Camel Case, Pascal Case, Kebab Case, and More](https://medium.com/@code.ceeker/naming-conventions-camel-case-pascal-case-kebab-case-and-more-dc4e515b9652)"
      ],
      "metadata": {
        "id": "iB0mDR0Oxwba"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "![1_PSDlLqeuDgeqClF-LLqPPw.png]()"
      ],
      "metadata": {
        "id": "yEcF87iYx3tt"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Special Naming Cases**\n",
        "\n",
        "<br>\n",
        "\n",
        "| Type                       | Example      | Used For                                 |\n",
        "|----------------------------|--------------|------------------------------------------|\n",
        "| Regular Variable           | total_cost   | General use                              |\n",
        "| Constant                   | PI = 3.14159 | Constants                                |\n",
        "| Class Name                 | BankAccount  | Class names                              |\n",
        "| Private Variable           | _password    | Internal use (not enforced)              |\n",
        "| Private with Name Mangling | __secret_key | Avoid accidental overrides in subclasses |\n",
        "| Special Method             | \\_\\_init\\_\\_     | Built-in methods                         |\n",
        "\n",
        "\n",
        "\n",
        "<br>\n",
        "<br>\n",
        "\n",
        "## Summary of Naming Conventions\n",
        "\n",
        "| Convention          | Used For                              | Example                       |\n",
        "|---------------------|---------------------------------------|-------------------------------|\n",
        "| snake_case          | Variables & functions                 | user_name, total_price        |\n",
        "| CamelCase           | Classes                               | BankAccount, DataScienceModel |\n",
        "| UPPER_CASE          | Constants                             | MAX_SPEED, PI                 |\n",
        "| _single_underscore  | Private variable (by convention)      | _config                       |\n",
        "| __double_underscore | Name mangling (avoid external access) | __password                    |\n",
        "| \\_\\_dunder\\_\\_          | Special methods                       | \\_\\_init\\_\\_, \\_\\_str\\_\\_             |"
      ],
      "metadata": {
        "id": "hUJh8H_41rea"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "Here are the naming conventions in Python with their respective names:\n",
        "\n",
        "1. **CapWords** or **PascalCase**: Class names\n",
        "2. **snake_case**: Variable names, function names, method names, module names, package names\n",
        "3. **UPPER_CASE**: Constant names\n",
        "4. **dunder** (double underscore): Special method names (e.g. `__init__`, `__str__`)\n",
        "\n",
        "<br>\n",
        "\n",
        "It's worth noting that the official Python style guide, PEP 8, recommends using **`CapWords`** for `class names` and **`snake_case`** for `variable names`, `function names`, and `other identifiers`.\n",
        "\n",
        "[PEP 8 – Style Guide for Python Code](https://peps.python.org/pep-0008/)"
      ],
      "metadata": {
        "id": "JtXFwRNtbt_V"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Assigning Different Values**\n",
        "\n",
        "We can assign different values to multiple variables simultaneously, making the code concise and easier to read."
      ],
      "metadata": {
        "id": "tqY2I40wzM97"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "x, y, z = 1, 2.5, \"Python\" # Using type hints while assigning mutiple variables simultaneously cause and error invalid syntax\n",
        "\n",
        "print(x, y, z)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "skxxwIIszMgB",
        "outputId": "257de658-ec42-460c-9a40-25d1f7b969a2"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "1 2.5 Python\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "x: int, y: float, z: str = 1, 2.5, \"Python\" # Using type hints while assigning mutiple variables simultaneously cause and error invalid syntax\n",
        "\n",
        "print(x, y, z)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 106
        },
        "id": "x6N8GJwrzSBr",
        "outputId": "62ef1ba0-d076-40ba-d4ec-fa494b5d44d0"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "error",
          "ename": "SyntaxError",
          "evalue": "invalid syntax (<ipython-input-2-1b71593066e5>, line 1)",
          "traceback": [
            "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-2-1b71593066e5>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m    x: int, y: float, z: str = 1, 2.5, \"Python\" # Using type hints while assigning mutiple variables simultaneously cause and error invalid syntax\u001b[0m\n\u001b[0m          ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Delete a Variable Using del Keyword**\n",
        "\n",
        "We can remove a variable from the namespace using the del keyword. This effectively deletes the variable and frees up the memory it was using."
      ],
      "metadata": {
        "id": "w6QolFk1z8-R"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Assigning value to variable\n",
        "x: int = 10\n",
        "print(x)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "8F-wQtAL0CJ6",
        "outputId": "9c8cb945-f1cf-4683-8444-8b6c1bdf5f1a"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "10\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Removing the variable from memory using del keyword\n",
        "del x"
      ],
      "metadata": {
        "id": "ujb5sHUz6Ypq"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# Trying to print x after deletion will raise an error\n",
        "# print(x)  # Uncommenting this line will raise NameError: name 'x' is not defined\n",
        "print(x) # NameError: name 'x' is not defined, because we already delete variable x (del x)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 141
        },
        "id": "Hxzw15lVzbcB",
        "outputId": "c6af1f3a-1cda-451a-9607-c316d96fdc4f"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "error",
          "ename": "NameError",
          "evalue": "name 'x' is not defined",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-29-ef036dc207a0>\u001b[0m in \u001b[0;36m<cell line: 0>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# NameError: name 'x' is not defined, because we already delete variable x (del x)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
            "\u001b[0;31mNameError\u001b[0m: name 'x' is not defined"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Explanation:\n",
        "\n",
        "`del` x removes the variable x from memory.\n",
        "After deletion, trying to access the variable x results in a NameError, indicating that the variable no longer exists."
      ],
      "metadata": {
        "id": "fyMwXRLE0P7y"
      }
    }
  ]
}